<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>回收站</title>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--Layui-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--extended-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/extended.css"/>
    <!--公用样式JS-->
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${re.contextPath}/plugin/common/js/comment.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.js" charset="utf-8"></script>
    <style>
        .project > div > a:nth-child(1) {
            margin-left: 0;
        }

        .layui-laypage-limits {
            width: 120px;
        }

        .layui-breadcrumb a:hover {
            color: #5775EF !important;
        }

        .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background: #5775EF;
        }
    </style>
</head>
<body>

<div style="background-color: #F1F4FB;padding-left: 20px;">
    <span class="layui-breadcrumb" lay-separator=">">
        <a><cite>考试管理</cite></a>
        <a href="/exam/list/index"><cite>考试列表</cite></a>
        <a href="#"><cite>回收站</cite></a>
    </span>
</div>

<div class="project whitebg" style="margin-top: 0;">
    <div class="clearfix">
        <a href="#" class="fl white ft14 " onclick="delAll()">删除全部</a>
        <a href="#" class="fl white ft14 btn_del" onclick="cancel()">返回</a>
        <a href="#" class="fl white ft14 btn_del" onclick="batchDel()">批量删除</a>
        <a href="#" class="fl white ft14 btn_del" onclick="hyAll()">批量还原</a>
    </div>
    <div>
        <table id="projectList" style="height: 400px;" class="layui-hide" lay-filter="project"></table>
    </div>
</div>

<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="hy">还原</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    var layer;
    var form = layui.form;
    var table = null;
    var tableIns = null;
    document.onkeydown = function (e) { // 回车提交表单
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            $(".select .select-on").click();
        }
    }
    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element = "";
    layui.use('element', function () {
        element = layui.element;
    });

    layui.use('table', function () {
        table = layui.table;
        element = element;
        //方法级渲染
        tableIns = table.render({
            id: 'projectList',
            elem: '#projectList',
            url: '/exam/list/selectKs?state=' + '000',
            cols: [[
                {type:'checkbox', fixed:'fixed'},
                {
                    title: '序号', width: '10%', templet: function (res) {
                        return res.LAY_INDEX;
                    },align:'center'
                },
                {field: 'examId', title: 'ID', hide: true, sort: false},
                {field: 'examName', title: '考试名称', width: '20%', sort: false},
                //{field: 'quCategory', title: '已参加人数', width: '10%', sort: false},
                //{field: 'quType', title: '及格人数', width: '10%', },
                //{field: 'level', title: '总数', width: '10%'},
                {field: 'passScore', title: '及格分', width: '20%'},
                {field: 'endTime', title: '考试结束时间', width: '30%'},
                {field: 'remark', title: '操作', width: '20%', toolbar: "#toolBar"}
            ]],
            page: true,
            height: 'full-110',
            done: function (res, currentCount) {
                //***重点***：table渲染完成后渲染element进度条
                element.render()
            }
        });

        //监听表格复选框选择
        table.on('checkbox(project)', function (obj) {
            //console.log(obj)
        });
        //监听工具条   还原
/*        table.on('tool(project)', function (obj) {
            console.log(obj)
            var data = obj.data;
            if (obj.event === 'hy') {
                layer.confirm('确定还原吗？', function (index) {
                    layerAjax("/exam/list/updateExam", {examId: data.examId, status: '001'}, '', function (d) {
                        if (d) {
                            layer.msg("操作成功", {icon: 1});
                            tableIns.reload();
                        } else {
                            layer.msg("操作失败", {icon: 2});
                        }
                    })
                });
            }
        });*/

        //删除
        table.on('tool(project)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除吗?', function (index) {
                    layerAjaxGet("/exam/list/delFromRecycle", {examId: data.examId}, '', function (d) {
                        if (d) {
                            layer.msg('操作成功', {icon: 1});
                            tableIns.reload();
                        } else {
                            layer.msg('操作失败', {icon: 2});
                        }
                    })
                })
            }else if (obj.event === 'hy') {
                layer.confirm('确定还原吗？', function (index) {
                    layerAjax("/exam/list/updateExam", {examId: data.examId, status: '001'}, '', function (d) {
                        if (d) {
                            layer.msg("操作成功", {icon: 1});
                            tableIns.reload();
                        } else {
                            layer.msg("操作失败", {icon: 2});
                        }
                    })
                });
            }
        })
    });


    function delAll() {
        layer.confirm('确定删除全部？删除之后将无法恢复！！！', function (index) {
            layerAjaxGet('/exam/list/deleteKs', {ids: ""}, '', function (d) {
                if (d.flag) {
                    var data = d.data;
                    layer.msg("操作成功", {icon: 1});
                    tableIns.reload();
                } else {
                    layer.msg(d.msg, {icon: 2});
                }
            })
        });
    }

    //取消
    function cancel() {
        window.parent._showtab('e0652f5faea74175be94ebf0d2a41dd6', '考试列表', '/exam/list/index');
    }

    //批量删除
    function batchDel() {
        var checkStatus = table.checkStatus('projectList');
        //获取选中数量
        var selectCount = checkStatus.data.length;
        if (selectCount > 0) {
            layer.confirm('确定将选择的项目彻底删除？删除之后将无法恢复！！！', function (index) {
                var ids = [];
                for (var i = 0; i < selectCount; i++) {
                    ids.push(checkStatus.data[i].examId);
                }
                $.ajax({
                    url: '/exam/list/deleteFromRecycle',
                    type: "post",
                    data: JSON.stringify(ids),
                    dataType: "json",
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.flag) {
                            layer.msg("删除成功", {icon: 1})
                            table.reload('projectList')
                        } else {
                            layer.msg(res.msg, {icon: 2})
                            return false;
                        }
                    }
                });
            });
        } else {
            layer.msg('请选择你要删除的考试', {icon: 2});
        }
    }


    //批量还原
    function hyAll() {
        var checkStatus = table.checkStatus('projectList');
        //获取选中数量
        var selectCount = checkStatus.data.length;
        if (selectCount > 0) {
            layer.confirm('确定还原吗', function (index) {
                var ids = [];
                for (var i = 0; i < selectCount; i++) {
                    ids.push(checkStatus.data[i].examId);
                }
                $.ajax({
                    url: '/exam/list/hyAll',
                    type: "post",
                    data: JSON.stringify(ids),
                    dataType: "json",
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.flag) {
                            layer.msg("还原成功", {icon: 1})
                            table.reload('projectList')
                        } else {
                            layer.msg(res.msg, {icon: 2});
                            return false;
                        }
                    }
                });
            });
        } else {
            layer.msg("请选择你要还原的考试。", {icon: 2})
        }
    }
</script>

</body>

</html>
